package com.tracemap.websender;

import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
//import org.apache.http.impl.client.
import org.apache.http.message.BasicNameValuePair;

import com.tracemap.websender.jsonparser.LocationJSON;


public class ReportLocation {
	String urlstr ="http://www.dengluyi.com:9080/mobile/reportme";
	
	public void put(String time,String latitude, String longtitude)
	{
		
        
        String geturl = urlstr + "?" + "time="+ time +"&latitude=" + latitude + "&longtitude=" + longtitude;
        HttpGet get = new HttpGet(geturl);
        DefaultHttpClient hc = new DefaultHttpClient();
        HttpHost proxy = new HttpHost("wwwgate0-ch.mot.com", 1080); 
        hc.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); 
        try {
            HttpResponse resp = hc.execute(get);
            if (resp.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK) {
                //Toast.makeText(HttpActivity.this, "Send Successfully", Toast.LENGTH_LONG).show();
            } else {
                //Toast.makeText(HttpActivity.this, "Send Failed", Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }        
	}
	public void post(String phonenumber,String latitude, String longtitude)
	{
		LocationJSON location = new LocationJSON(phonenumber,latitude,longtitude);
		
        
	    try {
	    	NameValuePair pair1 = new BasicNameValuePair("myloc", location.serialize());
	        //NameValuePair pair2 = new BasicNameValuePair("latitude", latitude);
	        //NameValuePair pair3 = new BasicNameValuePair("longtitude", longtitude);
	        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
	        pairs.add(pair1);
	        //pairs.add(pair2);
	        //pairs.add(pair3);
	        HttpEntity entity = new UrlEncodedFormEntity(pairs);
	        HttpPost post = new HttpPost(urlstr);
	        post.setEntity(entity);
	        DefaultHttpClient hc = new DefaultHttpClient();
	        //HttpHost proxy = new HttpHost("wwwgate0-ch.mot.com", 1080); 
	        //hc.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); 
	        
	        HttpResponse resp = hc.execute(post);
	        if (resp.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK) {
	            //Toast.makeText(HttpActivity.this, "Send Successfully", Toast.LENGTH_LONG).show();
	        } else {
	            //Toast.makeText(HttpActivity.this, "Send Failed", Toast.LENGTH_LONG).show();
	        }
	    } catch (Exception e) {
	        e.printStackTrace();
	    }
	}
}
